#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using Agresso.Interface.Layer.Service;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class DADeskVesselForm : Form, IVesselMappingForm
    {
        DaDeskVessel m_vessel;
        DADesk_PDA_Service m_daDeskService;
        UserControlDaDeskVesselMapping m_parent;

        public DADeskVesselForm(DaDeskVessel vessel, UserControlDaDeskVesselMapping parent)
        {
            InitializeComponent();
            Text = "Update Vessel";
            m_daDeskService = new DADesk_PDA_Service();
            m_parent = parent;
            m_vessel = vessel;
            textBoxVessel.Text = m_vessel.Vessel_Name;
            textBoxAgrVesselCode.Text = m_vessel.AgrVessel_Code;
            textBoxAgrVesselName.Text = m_vessel.AgrVessel_Name;
            textBoxAgrCCCode.Text = m_vessel.AgrVessel_CostCentre;
        }

        private void button1OK_Click(object sender, EventArgs e)
        {
            updateVessel();
            this.Close();
        }

        private void updateVessel()
        {
            m_vessel.AgrVessel_Code = textBoxAgrVesselCode.Text;
            m_vessel.AgrVessel_Name = textBoxAgrVesselName.Text;
            m_vessel.AgrVessel_CostCentre = textBoxAgrCCCode.Text;
            m_daDeskService.UpdateVessel(m_vessel);
            m_parent.UpdateSelectedItem(m_vessel);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonApply_Click(object sender, EventArgs e)
        {
            updateVessel();
            buttonApply.Enabled = false;
        }

        private void DADeskVesselForm_Load(object sender, EventArgs e)
        {
            textBoxAgrVesselCode.Focus();
        }

        private void activate_apply(object sender, KeyPressEventArgs e)
        {
            buttonApply.Enabled = true;
        }

        private void buttonSearch_Click(object sender, EventArgs e)
        {
            FindVesselForm frm = new FindVesselForm(this);
            frm.ShowDialog();
        }

        public void UpdateAgressoVessel(agldimvalue vessel)
        {
            textBoxAgrVesselCode.Text = vessel.dim_value;
            textBoxAgrVesselName.Text = vessel.description;
            textBoxAgrCCCode.Text = vessel.rel_value;
        }

        public string GetVesselName()
        {
            return textBoxVessel.Text;
        }
    }
}